package com.hushao.lims.weblims.service.impl;

import com.hushao.lims.weblims.domain.EquipmentInfo;
import com.hushao.lims.weblims.domain.EquipmentRepertory;
import com.hushao.lims.weblims.repository.EquipmentRepertoryRepository;
import com.hushao.lims.weblims.service.EquipmentRepertoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 930588706
 * @date 18/1/22
 * 器材库存
 */
@Service
public class EquipmentRepertoryServiceImpl implements EquipmentRepertoryService {
    @Autowired
    private EquipmentRepertoryRepository equipmentRepertoryRepository;
    private final int count=0;


    @Override
    public Page<EquipmentRepertory> listEquipmentByName(String equipmentName, Pageable pageable) {
        equipmentName="%"+equipmentName+"%";
        return equipmentRepertoryRepository.findByEquipmentCountGreaterThanAndEquipmentInfo_EquipmentNameLike(count,equipmentName,pageable);
    }

    @Override
    public EquipmentRepertory findByEquipment(EquipmentInfo equipmentInfo) throws Exception{
        EquipmentRepertory equipmentRepertory=equipmentRepertoryRepository.findByEquipmentInfo(equipmentInfo);
        return equipmentRepertory;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public EquipmentRepertory saveOrUpdate(EquipmentRepertory equipmentRepertory) throws Exception {
        return equipmentRepertoryRepository.save(equipmentRepertory);
    }
}
